#include "widget.h"
#include "ui_widget.h"
#include "childthread.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btnUpdate_clicked()
{
    ChildThread* ch = new ChildThread();

    //connect(ch, &ChildThread::sig_SendToUI, this, &Widget::showInfo);
    connect(ch, &ChildThread::sig_SendToUI,this, &Widget::showInfo);
    connect(ch, &ChildThread::sig2, this, &Widget::showInfo2);

    ch->start();

    qDebug()<< "ui thread id2 = " << QThread::currentThread();
}

void Widget::showInfo(Score s)
{
    string info = s.name + "id = " + to_string(s.id) + " age = " + to_string(s.age);
    ui->lineEdit->setText(QString::fromStdString(info));

}

void Widget::showInfo2(string name, int id)
{
    qDebug() << id;
    qDebug() << "name = " << QString::fromStdString(name);
}

